import "babel-polyfill";

import Vue from 'vue'


import App from "./App";
import store from "./store/";
import routerMap from "./router";


import VueRouter from "vue-router";
Vue.use(VueRouter);

// 滚动条
import vueScroll from "vuescroll";
import "vuescroll/dist/vuescroll.css";
Vue.use(vueScroll, {});

Vue.use(VueRouter);

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Vue.use(ElementUI, {
    size: "small"
});

import 'viewerjs/dist/viewer.css'
import Viewer from 'v-viewer'
Vue.use(Viewer)


import "./styles/base.css";
import "./styles/commonly.css";
import "./styles/element_.css";
import "./styles/util.css";

import base from "./utils/base";
Vue.use(base);

// 全局过滤
import filter from "./utils/filter";
for (let key in filter) {
    Vue.filter(key, filter[key]);
}
// 全局参数
import global from './utils/global'

// 通用 询问组件
import baseConfirm from './components/commons/baseConfirm/index.js';
Vue.use(baseConfirm);


// 腾讯im
import tim from './utils/tim';
import TIM from 'tim-js-sdk'

window.tim = tim;
window.TIM = TIM;

Vue.prototype.tim = tim;
Vue.prototype.TIM = TIM;
Vue.prototype.$bus = new Vue();

const router = new VueRouter({
    // hash history
    mode: "hash",
    base: __dirname,
    routes: routerMap
});


import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({ showSpinner: false });
import {
    Message
} from "element-ui";
router.beforeEach((to, from, next) => {
    NProgress.start()
    store.dispatch('GET_DICT', "").then((data) => {}).catch(() => {
        Message.error('数据字典获取异常！部分数据无法展示')
        store.dispatch('GET_DICT', "").then((data) => {}).catch(() => {
            Message.error('数据字典获取异常！部分数据无法展示')
        })
    })
    if (store.state.common.DoctorId) {
        if (store.state.common.DoctorSig) {
            next();
        } else {
            store.dispatch('GET_SIG', store.state.common.DoctorId).then((data) => {
                next();
            }).catch(() => {
                next();
            })

        }
    } else {
        let doctorId = localStorage.getItem("doctorId")
        if (store.state.common.DoctorSig) {
            next();
        } else {
            store.dispatch('GET_SIG', doctorId).then((data) => {
                next();
            }).catch(() => {
                next();
            })
        }
    }
});
router.afterEach(() => {
    NProgress.done()
})

window.$Vue = new Vue({
    store,
    router,
    global,
    render: h => h(App)
}).$mount("#app");